/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelCompetition2.java
 *
 * Created on 19-may-2010, 18:52:12
 */

package edu.ieslaferreria.creditsintesis.builders.Swing;

import edu.ieslaferreria.creditsintesis.logicgame.actions.RmiEvent;
import edu.ieslaferreria.creditsintesis.rmi.Client;
import edu.ieslaferreria.creditsintesis.rmi.EventIniciarInteraccion;
import edu.ieslaferreria.creditsintesis.rmi.EventPanelsInteractionTwoPlayersListener;
import edu.ieslaferreria.creditsintesis.rmi.GameEventInteracctionTwoPanels;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrador
 */
public class JPanelCompetition2 extends JPanelGame{
  private HashMap<String,List<String>> Options = new HashMap();
    
   EventIniciarInteraccion listenerComp;
     

 EventPanelsInteractionTwoPlayersListener listenerComunicationOtherPanel;
     /** Creates new form JPanelCompetition */
     public JPanelCompetition2(Client client) {
          initComponents();
          this.setClient(client);



/*evento para iniciarse tras goin, lanzado por main*/

//   listenerComp = new EventIniciarInteraccion(ui, WIDTH, true, null, pontPanel) {
//
//            public void action(RmiEvent event) throws RemoteException {
//
//                EventGoInInteracction ev = (EventGoInInteracction) event;
//
//                pontPanel =  ev.getPontPartidaInt();
//             setVisible(true);
//              }
//            };
///*evento para canviar informacion con el otro player ( panel)*/
            listenerComunicationOtherPanel = new EventPanelsInteractionTwoPlayersListener() {

            public void action(RmiEvent event) throws RemoteException {

            GameEventInteracctionTwoPanels ev = (GameEventInteracctionTwoPanels) event;



            jTextPane1.setText( "La prova elejida per "+ ev.getAlias().get(0) +"es "+ ev.getOpcions().get("prova") +
                                     " y el que vol si guanya es" + ev.getOpcions().get("premi"));

              };


            };
     }
    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jRadioButtonOk = new javax.swing.JRadioButton();
        jRadioButtonRebuig = new javax.swing.JRadioButton();
        jRadioButtonHuir = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();

        jRadioButtonOk.setText("Aceptar");
        jRadioButtonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonOkActionPerformed(evt);
            }
        });

        jRadioButtonRebuig.setText("Rebuig");
        jRadioButtonRebuig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonRebuigActionPerformed(evt);
            }
        });

        jRadioButtonHuir.setText("Huir");
        jRadioButtonHuir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonHuirActionPerformed(evt);
            }
        });

        jScrollPane1.setViewportView(jTextPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 508, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButtonRebuig)
                    .addComponent(jRadioButtonOk)
                    .addComponent(jRadioButtonHuir))
                .addGap(14, 14, 14))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jRadioButtonOk)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonRebuig)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonHuir)
                .addContainerGap(60, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonOkActionPerformed
        // TODO add your handling code here:


        this.Options.put(RESPOSTA_PROPOSICIO,toList(new String []{OK}));
        /*Start minigame Selected*/
        this.EnviarMensajeAlOtroPlayer();
    }//GEN-LAST:event_jRadioButtonOkActionPerformed

    private void jRadioButtonRebuigActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonRebuigActionPerformed
        // TODO add your handling code here:
        /*go again to competition panel*/
this.Options.put(RESPOSTA_PROPOSICIO,toList(new String []{NO}));
this.EnviarMensajeAlOtroPlayer();
        
    }//GEN-LAST:event_jRadioButtonRebuigActionPerformed

    private void jRadioButtonHuirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonHuirActionPerformed
        // TODO add your handling code here:
this.Options.put(RESPOSTA_PROPOSICIO,toList(new String []{FUGIR}));
this.EnviarMensajeAlOtroPlayer();
        /*start a minigame for scapescene*/
    }//GEN-LAST:event_jRadioButtonHuirActionPerformed
/*
    private void OtherPlayerHasSelected(GameEventInteracction evt) {
        // TODO add your handling code here:
        HashMap<String,Component> Toset =new HashMap();
        ArrayList<String>names = new ArrayList();
        Toset.put("JTextPanel",this.jTextPane1);
        names.add("JTextPanel");


    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton jRadioButtonHuir;
    private javax.swing.JRadioButton jRadioButtonOk;
    private javax.swing.JRadioButton jRadioButtonRebuig;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

    public void update(Map<String, List<String>> opcions,ArrayList<String> extras) {
        if(!opcions.get(OPCIO_BASICA).toString().equals("[]")){
        jTextPane1.setText("El otro player ha elegido la prueba " + opcions.get(OPCIO_BASICA));
        }
    }

    public void EnviarMensajeAlOtroPlayer(){
    ArrayList<String> alias = new ArrayList();
            alias.add(getClient().getNom());

        try {
        this.getPontPanel().send(new GameEventInteracctionTwoPanels(5,alias, Options, getPontPanel()));
        } catch (RemoteException ex) {
        Logger.getLogger(JPanelCompetition2.class.getName()).log(Level.SEVERE, null, ex);
        }
  
}

}
